// const fs = require('fs');
// const path = require('path');
import path from 'path'
import fs from 'fs'

export function getImageFilePaths(folderPath) {
    return new Promise((resolve, reject) => {
        fs.readdir(folderPath, (err, files) => {
            if (err) {
                reject('无法读取文件夹：' + err)
                return
            }

            const result = []
            files.forEach((file) => {
                if (/\.(jpg|jpeg|png|gif)$/i.test(file)) {
                    const filePath = path.join(folderPath, file)
                    result.push(filePath)
                }
            })

            resolve(result)
        })
    })
}

export function imageToBase64(imagePath) {
    return new Promise((resolve, reject) => {
        fs.readFile(imagePath, (err, data) => {
            if (err) {
                reject(err)
            } else {
                const base64Image = data.toString('base64')
                resolve(base64Image)
            }
        })
    })
}


